window.onload = function(){
// top 左侧鼠标移到地址显示隐藏的地址
	var top_l_p = document.getElementById('top_l_p');
	var top_address = document.getElementById('top_address');
	var top_r = document.getElementById('top_r');

	top_address.onmouseover = function(){
		top_l_p.style['padding'] = '0px 4px';
		top_l_p.style.backgroundColor = 'white';
		top_l_p.style['border-left'] = '1px solid #ddd';
		top_l_p.style['border-right'] = '1px solid #ddd';
		
	}
	top_address.onmouseout = function(){
		top_l_p.style = 'none';
	}
	top_l_p.onmouseover = function(){
		top_l_p.style['padding'] = '0px 4px';
		top_l_p.style.backgroundColor = 'white';
		top_l_p.style['border-left'] = '1px solid #ddd';
		top_l_p.style['border-right'] = '1px solid #ddd';
	}

// top 鼠标移上显示隐藏的二级菜单
	var top_r_over = document.getElementsByClassName('top_r_over');
	var top_r_hids = document.getElementsByClassName('top_r_hids');
	
	top_r_over[0].onmouseover = function(){
		top_r_hids[0].style.display = 'block';
	}
	top_r_over[0].onmouseout = function(){
		top_r_hids[0].style.display = 'none';
	}

	top_r_over[1].onmouseover = function(){
		top_r_hids[1].style.display = 'block';
	}
	top_r_over[1].onmouseout = function(){
		top_r_hids[1].style.display = 'none';
	}

	top_r_over[2].onmouseover = function(){
		top_r_hids[2].style.display = 'block';
	}
	top_r_over[2].onmouseout = function(){
		top_r_hids[2].style.display = 'none';
	}

	top_r_over[3].onmouseover = function(){
		top_r_hids[3].style.display = 'block';
	}
	top_r_over[3].onmouseout = function(){
		top_r_hids[3].style.display = 'none';
	}

	top_r_over[4].onmouseover = function(){
		top_r_hids[4].style.display = 'block';
	}
	top_r_over[4].onmouseout = function(){
		top_r_hids[4].style.display = 'none';
	}

// banner图左侧的一级菜单 鼠标移上显示二级菜单
	/**
	* i 表示左侧下标为 i 的一级菜单标为
	* n 表示左侧一级菜单 当前显示的 n个分类
	*/
	function dis(i,n){
		var nav_nav = document.getElementById('nav_nav');
		var nav_hids = document.getElementsByClassName('nav_hids');
		var oLi = nav_nav.getElementsByTagName('li');

		oLi[i].onmouseover = function(){
			nav_hids[i].style.display = 'block';
			oLi[i].style.backgroundColor = "white";
			for(var x=0; x<n; x++){
				oLi[i].getElementsByTagName('a')[x].style.color = "#C81623";
			}	
		}
		oLi[i].onmouseout = function(){
			nav_hids[i].style.display = 'none';
			oLi[i].style.backgroundColor = "#C81623";
			for(var x=0; x<n; x++){
				oLi[i].getElementsByTagName('a')[x].style.color = "white";
			}
		}
		nav_hids[i].onmouseover = function(){
			nav_hids[i].style.display = 'block';
			oLi[i].style.backgroundColor = "white";
			for(var x=0; x<n; x++){
				oLi[i].getElementsByTagName('a')[x].style.color = "#C81623";
			}
		}
		nav_hids[i].onmouseout = function(){
			nav_hids[i].style.display = 'none';
			oLi[i].style.backgroundColor = "#C81623";
			for(var x=0; x<n; x++){
				oLi[i].getElementsByTagName('a')[x].style.color = "white";
			}
		}
	}
	dis(0,2);
	dis(1,4);
	dis(2,3);
	dis(3,5);
	dis(4,5);
	dis(5,3);
	dis(6,5);
	dis(7,2);
	dis(8,3);
	dis(9,3);
	dis(10,5);
	dis(11,2);
	dis(12,4);
	dis(13,5);
	dis(14,5);

// banner轮播图
	var banner_m = document.getElementById('banner_m');
	var list = document.getElementById('list');
	var prve = document.getElementById('prve');
	var next = document.getElementById('next');
	var show = document.getElementById('show');
	var show_btn = show.getElementsByTagName('li');
	var index = 0;
	var animated = false; //轮播优化控制值
//按钮高亮
	function show_button(){
		for(var i=0; i<show_btn.length; i++){
			show_btn[i].className = '';
		}
		if(index>4){
			index = 0;
		}else if(index<0){
			index = 4;
		}
		show_btn[index].className = 'on';
	}
// 自动播放
	banner_m.onmouseover = stop;
	banner_m.onmouseout = play;
	play();
	function play(){
		timer = setInterval(function(){
			next.onclick();
		},2000); 
	}
// 停止播放
	function stop(){
		clearTimeout(timer);
	}
// 点击左右箭头切换图片
	function animate(offset){
		animated = true;
		var left = parseInt(list.style.left)+offset; //目标位移量、轮播要移动到的位置
		var time = 300; //位移总时间
		var interval = 300;  //位移间隔时间
		var speed = offset/(time/interval); //每次的位移量
		function go(){
			if((speed<0 && parseInt(list.style.left)>left) || (speed>0 && parseInt(list.style.left)<left)){
				list.style.left = parseInt(list.style.left)+speed+'px';
				setTimeout(go,interval);
			}else{
				animated = false;
				if(left<-3650){
					left = -730;
				}else if(left>-730){
					left = -3650;
				}
				list.style.left = left+'px';
			}
		}
		go();	
	}
	next.onclick = function(){
		if(!animated){
			animate(-730);
		}
		index++;
		show_button();
	}
	prve.onclick = function(){
		if(!animated){
			animate(730);
		}
		index--;
		show_button();
	}
// 点击按钮切换banner图
	for(var x=0; x<show_btn.length; x++){
		show_btn[x].onmouseover = function(){
			// 优化---如果点击的是当前显示的就结束、不运行下面的代码
			if(this.className == 'on'){
				return;
			}
			var my_index = parseInt(this.getAttribute('index'));
			var offset = -730*(my_index-index);
			if(!animated){
				animate(offset);
			}
			index = my_index;
			show_button();
		}
	}




























}